package org.goodsl.deploymap.test

import org.goodsl.deploymap.AppSystem
import org.goodsl.deploymap.Host
import org.goodsl.deploymap.Parser
import org.goodsl.deploymap.Service
import org.goodsl.deploymap.ServiceRelation
import org.goodsl.deploymap.ServiceType
import org.goodsl.deploymap.loader.DiskFolderLoader
import org.junit.Before
import org.junit.Test

/**
 * Created with IntelliJ IDEA.
 * User: Simon Xiao
 * Date: 12-12-19
 * Time: 下午4:55
 * Copyright goodsl.org 2012~2020
 */
class TestParse {

    String pathStr
    DiskFolderLoader loader

    @Before
    void setup(){

        pathStr = System.getProperty("user.dir") +
                File.separatorChar + "script" +
                File.separatorChar + "test"
        loader = new DiskFolderLoader(pathStr)
    }


    @Test
    void testLoad(){

        assert loader.scripts().length > 0
        loader.scripts().each {
            println  it
        }

    }

    @Test
    void testParseTopElement(){
        AppSystem sys = Parser.parse(loader)
        assert sys.envs.size() > 0
        assert sys.modules.size() >0
        assert sys.services.size() >0

        Service s1 = sys.getService("s1")

        assert s1

        assert s1.modules.size() > 0

        assert s1.relations.size() > 0

        s1.relations.each { ServiceRelation relation ->

            print(relation.nameA + " " + relation.relationType.toString())
            print(" " + relation.nameB )
            println(" [" + relation.desc + "]" )

        }

        assert s1.publicAccess
        assert s1.type == ServiceType.web
        assert s1.introduced

    }
    @Test
    void testDeploy(){
        AppSystem sys = Parser.parse(loader)
        Host host = sys.getEnv("net").hosts.get(0);
        assert  host
        assert host.hostService.size() == 2
    }

}
